{
  "properties" : { },
  "id" : "aacd20e9b1954880ac00a72b40c60fce",
  "script" : null,
  "groupId" : "bcdec4ef1ba74815bea2c09a20056b65",
  "name" : "添加",
  "createTime" : null,
  "updateTime" : 1736693832978,
  "lock" : null,
  "createBy" : "管理员",
  "updateBy" : "可辉",
  "path" : "add",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ {
    "name" : "permission",
    "value" : "system:uhgl",
    "description" : "允许拥有该权限的访问",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "requestBody" : "{\"name\":\"tt2\",\"username\":\"tt2\",\"password_new\":\"123\",\"memo\":\" \",\"unitId\":1}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 500,\n    \"msg\": \"核心信息缺失添加失败\"\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
import com.wiwf.model.bean.SysUserBean
import org.springframework.util.ObjectUtils
import 'org.springframework.security.crypto.password.PasswordEncoder' as pwdEncoder;
import 'com.wiwf.model.security.service.SysTokenService' as sysTokenService;
import 'com.wiwf.model.security.service.SysUserService' as sysUserService;
import 'com.wiwf.model.mapper.admin.dao.SysUserMapper' as sysUserMapper;

import 'com.wiwf.model.mapper.admin.dao.SysUnitUserRoleMapper' as sysUnitUserRoleMapper;

    if(body.password_new != null){
        body.password = pwdEncoder.encode(body.password_new);
        body.password_new = null;
    }

    var user = sysTokenService.getTokenUser(cookie[sysTokenService.getTokenKey()]);
    body.creatorId = user.getUserId();
    body.creatorName = user.getName();

    if(body.userId != null){
        SysUserBean sysUser = sysUserMapper.getById(new Integer(body.userId));
        
        if(! ObjectUtils.isEmpty(body.password)){
            sysUser.setPassword(body.password);
        }
        if(! ObjectUtils.isEmpty(body.nonLock)){
            sysUser.setNonLock(new Integer(body.nonLock));
        }
        if(! ObjectUtils.isEmpty(body.nonExpired)){
            sysUser.setNonExpired(new Integer(body.nonExpired));
        }
        if(! ObjectUtils.isEmpty(body.isEnabled)){
            sysUser.setIsEnabled(new Integer(body.isEnabled));
        }
        if(! ObjectUtils.isEmpty(body.memo)){
            sysUser.setMeno(body.memo);
        }
        return sysUserMapper.update(sysUser);
    } else if(ObjectUtils.isEmpty(body.username) || ObjectUtils.isEmpty(body.name)){

        exit 500, '核心信息缺失添加失败';
    } else {
        body.nonLock = 1;
        body.nonExpired = 1;
        body.nonExpiredC = 1;
        body.isEnabled = 1;
    }

try {
    var bl = sysUserService.save(body);
} catch(e) {
    exit 500, '添加失败';
}

user = sysUserService.getByColumn('username', body.username);

return sysUnitUserRoleMapper.save({'unitId': 1, 'roleId': 2, 'userId': user.userId});